package animation.sort.gui;

import animation.core.AlgorithmMonitorModel;

import javax.swing.*;
import java.awt.*;
import java.awt.font.TextAttribute;
import java.util.Map;
import java.util.HashMap;

/**
 * Created by IntelliJ IDEA.
 * User: Pablo
 * Date: Aug 9, 2008
 * Time: 4:31:24 AM
 * To change this template use File | Settings | File Templates.
 */
public class MonitoringArea extends JComponent {

    private Dimension minSize;
    private AlgorithmMonitorModel model;
    private Font boldVerdana = new Font("Verdana", Font.BOLD, 12);
    private Font verdana = new Font("Verdana", Font.PLAIN, 14);

    public MonitoringArea() {
        minSize = new Dimension(700, 50);
        setMinimumSize(minSize);
        setBorder(BorderFactory.createLoweredBevelBorder());
        setBackground(Color.WHITE);
        setOpaque(true);
    }


    public Dimension getPreferredSize()
    {
        return minSize;
    }

    public void setModel(AlgorithmMonitorModel model){
        this.model = model;
    }


    protected void paintComponent(Graphics g)
    {

        ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                           (RenderingHints.VALUE_TEXT_ANTIALIAS_ON));
        g.setColor(Color.WHITE);
        final int width = getWidth();
        final int height = getHeight();
        g.fillRect(0, 0, width, height);
        g.setColor(Color.BLUE);
        if (model != null){
            int y = 15;
            int step = 15;


//            Map<TextAttribute, Object> attribs = new HashMap<TextAttribute, Object>();
//            attribs.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);

//            Font underlined = verdana.deriveFont(attribs);
//            g.setFont(underlined);

//            g.drawString(model.getAlgorithmName(), 10, y);
//            y += step;
            
            g.setFont(boldVerdana);
            Map<String,String> map = model.getVariables();
            for (Map.Entry<String, String> entry : map.entrySet()) {
                g.drawString(entry.getKey() + ": " + entry.getValue(), 10, y);
                y += step;
            }

            y = 15;
            Map<String,String> imap = model.getInvariants();
            for (Map.Entry<String, String> entry : imap.entrySet()) {
                g.drawString(entry.getKey() + ": " + entry.getValue(), 110, y);
                y += step;
            }

            y = 15;
            Map<String, Integer> cmap = model.getCounters();
            for (Map.Entry<String, Integer> entry : cmap .entrySet()) {
                g.drawString(entry.getKey() + ": " + entry.getValue(), 240, y);
                y += step;
            }


        }
    }

}
